package com.pek.Exception;

import com.pek.util.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionHand {

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(TokenException.class)
    public RestResult<?> handleUseTokenException(TokenException e) {
        return new RestResult<>(401, false, e.getMessage(), null);
    }

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(PermitException.class)
    public RestResult<?> handlePermitException(PermitException e) {
        return new RestResult<>(403, false, e.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public RestResult<?> handleException(Exception e) {
        log.error(e.getMessage(), e);
        return RestResult.error(e.getMessage());
    }
}